
#include "server.h"
#include "public.h"

/*
 g++ -ggdb  main.cpp server.cpp   session.cpp Image.pb.cc  `pkg-config --cflags --libs opencv4` -lboost_filesystem -lboost_thread -lboost_system  -I/opt/boost_1_75_0/  -L/opt/boost_1_75_0/stage/lib  `pkg-config --cflags --libs protobuf` -lpthread -Dlinux -ldl libimageTensorProcess.so -Wl,-rpath,./ -std=c++11 -o server_proto2.out   

*/

int main(int argc, char *argv[])
{
    try
    {
        if (argc != 2)
        {
            std::cerr << "Usage: async_tcp_echo_server <port>\n";
            return 1;
        }

        boost::asio::io_context io_context;

        server s(io_context, std::atoi(argv[1]));

        io_context.run();
    }
    catch (std::exception &e)
    {
        std::string strTime = boost::posix_time::to_iso_string(

            boost::posix_time::second_clock::local_time());

        int pos = strTime.find('T');

        strTime.replace(pos, 1, std::string("-"));

        strTime.replace(pos + 3, 0, std::string(":"));

        strTime.replace(pos + 6, 0, std::string(":"));
        std::cerr << "Exception: " << e.what() << " " << __LINE__ << __FILE__ << "at " << strTime << endl;
    }

    return 0;
}

int session::ucharToMat(const uint8_t *p2, cv::Mat &src, int flag)
{
    int img_width = src.cols;
    int img_height = src.rows;
    //Mat img(Size(img_width, img_height), CV_8UC3);
    for (int i = 0; i < img_width * img_height * 3; i++)
    {
        src.at<cv::Vec3b>(i / (img_width * 3), (i % (img_width * 3)) / 3)[i % 3] = p2[i];
    }
    flag = 1;
    return flag;
}
